<?php
namespace core\lib;

use core\lib\config;

class route{
    public $control;
    public $action;

    public function __construct()
    {
        $path = $_SERVER['REQUEST_URI'];
        $path_trim = trim($path,'/');
        $path_arr = explode('/',$path_trim);
        unset($path_arr[0]);
        if (isset($path_arr[1])){
            if($path_arr[1] == 'index.php'){
                $path_arr[1] = $path_arr[2];
                $path_arr[2] = $path_arr[3];
            }
            if(isset($path_arr[1]) && isset($path_arr[2])){
                $this->control = $path_arr[1];
                unset($path_arr[1]);
                $pathtwo = explode('?',$path_arr[2]);
                $this->action = $pathtwo[0];
                unset($path_arr[2]);
            }else{
                $this->control = config::get('CONTROL','route');
                $this->action = config::get('ACTION','route');
            }
        }else{
            $this->control = config::get('CONTROL','route');
            $this->action = config::get('ACTION','route');
        }

        /*$count = count($path_arr);
        for ($i = 3;$i<$count+3;$i=$i+2){
            $_GET[$path_arr[$i]] = $path_arr[$i+1];
        }
        P($_GET);*/
    }
}